package com.zzptc.shop.db;

import java.sql.*;
import java.util.Map;

public class GoodIDB implements IDB{

    private Connection conn;
    private Map map;
    private String DRIVER="com.mysql.jdbc.Driver";
    private String URL="jdbc:mysql://localhost:3306/easybuy?useUnicode=true&characterEncoding=utf8";
    private String UNAME="root";
    private String PASS="root";
    private String CHARACTER;


    @Override
    public Connection getConn() throws SQLException {

        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        conn=DriverManager.getConnection(URL,UNAME,PASS);

        return conn;
    }

    @Override
    public void closeAll(Connection conn, PreparedStatement ps, ResultSet rs) throws SQLException {
        if (conn!=null&&!conn.isClosed()) {
            conn.close();
        }
        if (ps!=null) {
            ps.close();
        }
        if (rs!=null) {
            rs.close();
        }
    }

    public static void main(String[] args) {
        GoodIDB db=new GoodIDB();
        try {
            db.getConn();
            System.out.println(db.getConn().isClosed());
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }
}
